import * as api from '@/pages/api'
export default {
    namespaced: true,
    state: {
        productData:[]
    },
    getters: {
        
    },
    mutations: {
        SET(state,payload){
            state.productData = payload
        },
        DECREASE_INVENTORY(state,payload){
            console.log(payload);
            let target = state.productData.find(item=>item.id===payload)
            if (target) {
                target.inventory--
            }
        },
        DDDJIAJIA(state,payload){
            let target = state.productData.find(item=>item.id===payload)
            if (target) {
                target.inventory++
            }
        }
    },
    actions: {
       async FETCH(context,payload){
            let res = await api.fetchProduct()
            console.log(res);
            context.commit('SET',res.data)
        },
    }
}